package com.suxin.pgsharding;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

/**
 * @Classname AbstractPgSharding
 * @Description [ TODO ]
 * @Author Tang
 * @Date 2020/12/17 11:30
 * @Created by ASUS
 */
public abstract class AbstractPgSharding<T> {

    protected List<T> selectList(String sql, ResultSetParser parser) {

        List<T> list = new ArrayList<>();
        ResultSet resultSet = null;

        System.out.println("do something....start");

        try {
            parser.parse(resultSet);
        } catch (Exception e) {
            e.printStackTrace();
        }

        System.out.println("do something....end");

        return list;
    }

    /**
     * 查询结果
     */
    protected interface ResultSetParser{
        <T> T parse(ResultSet rs) throws Exception;
    }

    /**
     * 模板方法
     * @return
     */
    public abstract List<T> selectList();

}